package com.goods.business.converter;

import com.goods.common.model.business.Product;
import com.goods.common.vo.business.ProductStockVO;
import com.goods.common.vo.business.ProductVO;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

public class ProductConverter {
    public static List<ProductVO> converterToProductVO(List<Product> products) {
        if (!CollectionUtils.isEmpty(products)){
            List<ProductVO> productVOList = new ArrayList<>();
            for (Product product : products) {
                ProductVO productVO = new ProductVO();
                BeanUtils.copyProperties(product,productVO);
                productVOList.add(productVO);
            }
            return productVOList;
        }
        return null;
    }

    public static ProductVO converterToProductVOSimple(Product product) {
        if (product != null){
            ProductVO productVO = new ProductVO();
            BeanUtils.copyProperties(product,productVO);
            return productVO;
        }
        return null;
    }

    public static List<ProductStockVO> converterToProductStockVOList(List<Product> productList) {
        if (!CollectionUtils.isEmpty(productList)){
            List<ProductStockVO> productStockVOS = new ArrayList<>();
            for (Product product : productList) {
                ProductStockVO productStockVO = new ProductStockVO();
                productStockVO.setId(product.getId());
                productStockVO.setImageUrl(product.getImageUrl());
                productStockVO.setModel(product.getModel());
                productStockVO.setName(product.getName());
                productStockVO.setPNum(product.getPNum());
                productStockVO.setUnit(product.getUnit());

                productStockVOS.add(productStockVO);
            }
            return productStockVOS;
        }
        return null;
    }
}
